﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NumericTypeGeer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void IntegralOnlyCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            MustBePreciseCheckbox.Visible = !IntegralOnlyCheckbox.Checked;

            RecalculateSuggestedType();
        }


        private void MustBePreciseCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            RecalculateSuggestedType();
        }



        private void txtMaxValue_TextChanged(object sender, EventArgs e)
        {
            RecalculateSuggestedType();
        }



        private void txtMinValue_TextChanged(object sender, EventArgs e)
        {
            RecalculateSuggestedType();
            ValidateMinAndMaxValues();
        }

        private void ValidateMinAndMaxValues()
        {

        }

        private void RecalculateSuggestedType()
        {

        }

        private void txtMinValue_KeyPress(object sender, KeyPressEventArgs e)
        {
            var textBox = (TextBox)sender;
            if (!IsValidInput(e.KeyChar, textBox))
            {
                e.Handled = true;
            }
        }

        private bool IsValidInput(char keyChar, TextBox textBox)
        {
            return char.IsControl(keyChar) ||
                char.IsDigit(keyChar) ||
                (keyChar == '-' && textBox.SelectionStart == 0);
        }

        private void SetColorOfMaxValueTextField()
        {
            bool isValid = true;

            if (IsInputComplete())
            {
                var minValue = BigInteger.Parse(txtMinValue.Text);
                var maxValue = BigInteger.Parse(txtMaxValue.Text);
                if (maxValue < minValue)
                {
                    isValid = false;
                }
            }
            txtMaxValue.BackColor = isValid ? Color.White : Color.Red;
        }

        private bool IsInputComplete()
        {
            return txtMinValue.Text.Length > 0 &&
                txtMinValue.Text != "-" &&
                   txtMaxValue.Text.Length > 0 &&
                   txtMaxValue.Text != "-";
        }


    }
}


